<?php
	require "../common/db.inc";
	$conn = new mysqli($host, $username, $password, $dbname);	
	$conn->query("set names 'utf8'");	
	
	$id = $_REQUEST["hdID"];
	$title = $_REQUEST["txtTitle"];
	$type = $_REQUEST["cmbType"];
	$field = $_REQUEST["cmbField"];
	$category = $_REQUEST["cmbCat"];
	$author = $_REQUEST["txtAuthor"];
	$publisher = $_REQUEST["txtPublisher"];
	if($publisher == "")
		$publisher = "unknown";
	$pagenum = $_REQUEST["txtPageNum"];
	$desc = $_REQUEST["txtDesc"];
	$image_up = $_FILES["fImage"]["name"];
	
	session_start();
	$_SESSION["edit_title"] = $title;
	$_SESSION["edit_type"] = $type;
	$_SESSION["edit_category"] = $category;
	$_SESSION["edit_author"] = $author;
	$_SESSION["edit_publisher"] = $publisher;
	$_SESSION["edit_pagenum"] = $pagenum;
	$_SESSION["edit_desc"] = $desc;
	
	echo $_FILES["fImage"]["name"];
	if($image_up == "")
	{
		$image_up = $_REQUEST["hdImage"];
	}
	else
	{
		if ($_FILES["fImage"]["size"]/1000 < 3)
		{	
			if ($_FILES["fImage"]["error"] > 0)
			{
				header("Location: debook_edit.php?id=$id&errorImg=other");
			}
			else
			{
				if (file_exists($image .$image_up))
				{
					$image_up = time().$image_up;
				}
				
				move_uploaded_file($_FILES["fImage"]["tmp_name"], $image . $image_up);			
			}
		}	
		else
		{
			header("Location: ebook_edit.php?id=$id&errorImg=size");
		}
	}
	
	
	$strSQL = "call sp_UpdateEbookInfo('$id', '$title', '$type', '$desc', '$author', '$publisher', '$pagenum', '$image_up', '$category')";
	echo $strSQL;
	$conn->query($strSQL);	
	$conn->close();
	header("Location: XemChiTietSach.php?id=$id");

?>
	